package work.MrSun.xyq.util.isCollect;

import work.MrSun.xyq.model.XyqCollect;
import work.MrSun.xyq.model.XyqUser;
import work.MrSun.xyq.service.XyqCollectService;
import work.MrSun.xyq.service.XyqUserService;

/**
 * 收藏的公共方法
 */
public class IsCollect {

    private Integer code;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }


    public IsCollect isTrue(Integer userId, Integer messageId, XyqCollectService mangoCollectService, XyqUserService mangoUserService) {

        IsCollect isCollect = new IsCollect();
        isCollect.setCode(500);
        XyqUser user = mangoUserService.getById(userId);
        if (user == null) {
            isCollect.setCode(400);
            return isCollect;
        }

        XyqCollect mangoCollect = new XyqCollect();
        mangoCollect.setUserId(userId);
        mangoCollect.setMessageId(messageId);
        mangoCollectService.add(mangoCollect);
        isCollect.setCode(200);
        return isCollect;
    }
}
